<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Insert title here</title>
    <link type="text/css" rel="stylesheet" href="/BhSyCase/css/up.css">
</head>
<style>
    #myta{
        display: none;
    }
    #mytab{
        display: none;
    }

</style>
<body id="bo">
<div id = "Dx">
    <select id="mysel" onchange="cx()" name="y">
        <option>请选择月份</option>
    </select>
    <select id="myta" onchange="x()" name="t">
        <option>请选择查询到的天数</option>
    </select>
    <table id = "mytab" class="dataintable">
        <tr>
            <th>老师id</th>
            <th>学生名字</th>
            <th>班级</th>
            <th>时间</th>
            <th>情况</th>
        </tr>
    </table>
</div>
</body>
<script type="text/javascript">
    var http=new XMLHttpRequest();//发请求
    //网页打开时
    window.onload=function(){
        http.open("GET","stcx/region",true);
        http.send();
    }

    http.onreadystatechange=function(){
        if (http.readyState==4 && http.status==200) {
            var info=http.responseText;
            var sz=JSON.parse(info);
            var sel=document.querySelector("#mysel");
            for (var i = 0; i < sz.length; i++) {
                var op=new Option(sz[i],sz[i]);//里面的值//显示的值
                sel.appendChild(op);
            }
        }
    }
    function x() {
            var td = document.getElementById ("mytab");
        td.style.display='block';
            //清除td的值
            //td.innerHTML = '';
            //只清楚内容，不清除表格
            for(var k=td.rows.length-1;k>0;k--){
                td.deleteRow(k)
            }

            var dq=document.querySelector("#mysel");//获取下拉框的值
            var op=dq.value;
            var dq1=document.querySelector("#myta");//获取下拉框的值
            var op1=dq1.value;
            console.log(op1);
            http.open("GET","stcx/selxx?y="+op+"&t="+op1,true);//2//路径//同步还是异步
            http.send();
            http.onreadystatechange=function() {
                if (http.readyState == 4 && http.status == 200) {
                    var info = http.responseText;//响应文本
                    var sz = JSON.parse(info);
                    console.log(info);
                    var mytb = document.querySelector("#mytab");
                    var tr = mytb.insertRow();
                    // tr.insertCell().innerHTML = "老师id";
                    // tr.insertCell().innerHTML = "学生id";
                    // tr.insertCell().innerHTML = "班级";
                    // tr.insertCell().innerHTML = "时间";
                    // tr.insertCell().innerHTML = "情况";
                    //console.log(bhu);
                    for (var i = 0; i < sz.length; i++) {
                        var tr = mytb.insertRow();
                        //innerrText
                        tr.insertCell().innerHTML = sz[i].tid;
                        tr.insertCell().innerHTML = sz[i].uName;
                        tr.insertCell().innerHTML = sz[i].uclass;
                        //new SimpleDateFormat("yyyy-MM-dd").format(new Date())
                        tr.insertCell().innerHTML =sz[i].date ;
                        if(sz[i].workflag==0){
                            tr.insertCell().innerHTML ="没完成";
                        }else if(sz[i].workflag==1){
                            tr.insertCell().innerHTML ="已完成";
                        }
                        //tr.insertCell().innerHTML = sz[i].workflag;

                    }
                }
            }
    }
    // function bhuser(op,op1) {
    //     http.open("GET","stcx/selname?y="+op+"&t="+op1,true);//2//路径//同步还是异步
    //     http.send();
    //     var sz = null;
    //     http.onreadystatechange=function() {
    //         if (http.readyState == 4 && http.status == 200) {
    //             var bhuserB = http.responseText;
    //             sz =  JSON.parse(bhuserB);
    //             console.log(sz);
    //         }
    //     }
    // }
    function cx(){
         var td = document.getElementById("myta");
         td.style.display='block';
         //清除td的值
        td.innerHTML = '';
        // for(var k=td.rows.length-1;k>0;k--){
        //     td.deleteRow(k)
        // }

        var dq=document.querySelector("#mysel");//获取下拉框的值
        var op=dq.value;
        http.open("GET","stcx/selt?y="+op,true);//2//路径//同步还是异步
        http.send();

        http.onreadystatechange=function(){
            if (http.readyState==4 && http.status==200) {
                var info=http.responseText;
                var sz=JSON.parse(info);
                var sel=document.querySelector("#myta");
                var op1 = document.createElement("option");
                op1.innerText = "请选择天数";
                sel.appendChild(op1);
                for (var i = 0; i < sz.length; i++) {
                    var op = document.createElement("option");
                    op.innerText=sz[i];
                    sel.appendChild(op);
                }
            }

        }

    }

</script>
</html>
